<template>
	<div class="tjzj">
		<h1 class="bttt">添加专家</h1>
		<!-- <div class="img"><tailoring></tailoring></div> -->
		<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
			<el-form-item label="姓名" prop="Name"><el-input v-model="ruleForm.Name"></el-input></el-form-item>
			<el-form-item label="电话" prop="Phone"><el-input v-model="ruleForm.Phone"></el-input></el-form-item>
			<el-form-item label="密码" prop="Password"><el-input placeholder="请输入密码" v-model="ruleForm.Password" show-password></el-input></el-form-item>
			<el-form-item label="单位" prop="Company">
				<el-select v-model="ruleForm.Company" placeholder="请选择单位">
					<el-option v-for="c in companys" :label="c" :value="c" :key="c">{{ c }}</el-option>
				</el-select>
			</el-form-item>

			<el-form-item label="状态" prop="Status">
				<el-switch v-model="ruleForm.Status" active-color="#13ce66" inactive-color="#ff4949" @change="handleStatus(ruleForm.Status)"></el-switch>
			</el-form-item>

			<el-form-item label="专业领域" prop="Specialty">
				<!--<el-input v-model="ruleForm.Specialty"></el-input>-->
				<el-select v-model="ruleForm.Specialty" placeholder="请选择单位">
					<el-option v-for="c in Specialtys" :label="c" :value="c" :key="c">{{ c }}</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="性别" prop="Sex">
				<el-radio-group v-model="ruleForm.Sex">
					<el-radio label="男"></el-radio>
					<el-radio label="女"></el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="号码牌编号" prop="NumberCard">
				<el-input v-model="ruleForm.NumberCard">
					<template slot="prepend">
						0010-
					</template>
				</el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="addTExpert('ruleForm')" class="save">保存</el-button>
				<el-button type="warning" @click="resetForm('ruleForm')">重置</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
import tailoring from './Tailoring.vue';
import dayjs from 'dayjs';
export default {
	name: 'extianjia',
	components: {
		tailoring,
		dayjs
	},
	data() {
		return {
			companys: ['济南一院', '济南二院', '济南三院', '济南五院', '济南六院', '山东一院', '山东二院'],
			Specialtys: ['眼科', '儿科', '妇科', '外科', '内科', '其他'],
			ruleForm: {
				Name: 'Ceshi0001',
				Sex: '男',
				Phone: '19861601001',
				Password: 'cs000001',
				Status: true,
				Specialty: '骨科',
				Company: '济南市中心医院',
				NumberCard: '001'
			},
			rules: {
				Name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
				Phone: [{ required: true, message: '手机号不能为空', trigger: 'blur' }, { pattern: /^[1][35789]\d{9}$/, message: '请输入正确的手机号' }],
				Password: [
					{ required: true, message: '密码不能为空', trigger: 'blur' },
					{ pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/, message: '长度至少为8，至少含有一个字母和一个数字' }
				],

				// Specialty: [{ type: 'array', required: true, message: '请至少选择一个专业领域', trigger: 'change' }],
				Company: [{ required: true, message: '请选择工作单位', trigger: 'change' }],
				NumberCard: [{ required: true, message: '会员编号不能为空', trigger: 'blur' }, { pattern: /^[0-9]\d{2}$/, message: '会员编号为六位数字' }]
			}
		};
	},
	methods: {
		resetForm(formName) {
			this.$refs[formName].resetFields();
		},
		handleStatus(value) {
			console.log(value);
			// value.Status=! value.Status
			this.Status = !this.Status;
		},
		addTExpert(formName) {
			this.$refs[formName].validate(valid => {
				if (valid) {
					// alert("规则验证成功！")
					console.log(this.ruleForm);
					let that = this;
					let obj = {
						headImg: 'ceshiImage',
						expertName: that.ruleForm.Name,
						sex: that.ruleForm.Sex,
						phone: that.ruleForm.Phone,
						password: that.ruleForm.Password,
						// email:that.ruleForm2.Email,
						// status:that.ruleForm.Status,
						status: that.ruleForm.Status ? '1' : '0',
						createDate: dayjs().format('YYYY-MM-DD HH:mm:ss'),
						lastTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
						company: that.ruleForm.Company,
						specialty: that.ruleForm.Specialty,
						numberCard: '0010' + that.ruleForm.NumberCard
						// auditBy:2,
						// auditDate:dayjs().format('YYYY-MM-DD HH:mm:ss'),
					};
					// console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'))
					this.$axios.post('http://localhost:7070/api/Administration/AddTExpert', that.$qs.stringify(obj)).then(function(response) {
						// alert("返回值："+response.data)
						if (response.data) {
							alert('添加成功！');
							// that.$router.push({'path':'/index/bottom'})
						} else alert('添加失败！');
					});
				} else {
					console.log('ERROR！ 格式错误!!');
					return false;
				}
			});
		}
	}
};
</script>

<style scoped="scoped">
.demo-ruleForm {
	width: 30%;
	margin: 0 auto;
}
.bttt {
	width: 300px;
	margin: 0 auto;
	margin-bottom: 50px;
}
.img {
	width: 490px;
	margin: 0 auto;
}
.save {
	margin-right: 60px;
}
</style>
